﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Retirement_Admin_withdrawalTerminate : System.Web.UI.Page
{
    Dictionary<string, string> targetPercentageOrAmount = new Dictionary<string, string>();

    protected void Page_Load(object sender, EventArgs e)
    {
        int custId = -1;

        if (Session["userID"] == null)
        {
            custId = 15369472;//TODO GET FROM SESSION

        }
        else
        {
            custId = Convert.ToInt32(Session["userID"]);

        }

        List<Policy> policies = Policy.getPolicy(custId);
        Policy policy = policies.ElementAt(0);

        UserAccount userAccount = UserAccount.getUserAccountByAccountId(policy.accountId);
        this.lb_accountNumber.Text = userAccount.branchCode + "-" + userAccount.accountNumber + "-" + userAccount.accountTypeCode;
    }
    protected void btn_withdrawalTerminateRequest_Click(object sender, ImageClickEventArgs e)
    {
        int custId = -1;

        if (Session["userID"] == null)
        {
            custId = 15369472;//TODO GET FROM SESSION

        }
        else
        {
            custId = Convert.ToInt32(Session["userID"]);

        }

        List<Policy> policies = Policy.getPolicy(custId);
        Policy policy = policies.ElementAt(0);

        Requests requests = new Requests();
        PolicyRules policyRules = new PolicyRules();

        requests.policyNo = policy.policyNo;
        requests.reason = this.tb_reason.Text;

        this.getWithdrawalFundRequest();
        requests.fundWithdrawalRequest(targetPercentageOrAmount);
        this.Response.Redirect("./requestSuccessful.aspx");   
    }

    protected void btn_cancelRequest_Click(object sender, ImageClickEventArgs e)
    {
        this.Response.Redirect("./myPolicy.aspx");
    }

    private void getWithdrawalFundRequest()
    {
        //targetPercentageOrAmount to withdrawal from selected funds
        if (!Util.IsBlank(ddl_withdrawalFund1.SelectedValue))
        {
            targetPercentageOrAmount.Add(ddl_withdrawalFund1.SelectedValue, this.tb_withdrawalPercentageOrAmount1.Text);
        }

        if (!Util.IsBlank(ddl_withdrawalFund2.SelectedValue))
        {
            targetPercentageOrAmount.Add(ddl_withdrawalFund2.SelectedValue, this.tb_withdrawalPercentageOrAmount2.Text);
        }

        if (!Util.IsBlank(ddl_withdrawalFund3.SelectedValue))
        {
            targetPercentageOrAmount.Add(ddl_withdrawalFund3.SelectedValue, this.tb_withdrawalPercentageOrAmount3.Text);
        }

        if (!Util.IsBlank(ddl_withdrawalFund4.SelectedValue))
        {
            targetPercentageOrAmount.Add(ddl_withdrawalFund4.SelectedValue, this.tb_withdrawalPercentageOrAmount4.Text);
        }

        if (!Util.IsBlank(ddl_withdrawalFund5.SelectedValue))
        {
            targetPercentageOrAmount.Add(ddl_withdrawalFund5.SelectedValue, this.tb_withdrawalPercentageOrAmount5.Text);
        }

        if (targetPercentageOrAmount.Keys.Count == 0)
        {
            return;
        }
    }

}